package top.jle.locker.service;

import lombok.RequiredArgsConstructor;
import org.noear.solon.cloud.service.CloudLockService;
import top.jle.locker.integration.Locker;

@RequiredArgsConstructor
public class CloudLockServiceRedissonImpl implements CloudLockService {

    private final Locker locker;

    @Override
    public boolean tryLock(String group, String key, int seconds, String holder) {
        return locker.tryLock(group,key,seconds);
    }

    @Override
    public void unLock(String group, String key, String holder) {
        locker.getLock(group,key).unlock();
    }

    @Override
    public boolean isLocked(String group, String key) {
        return locker.getLock(group,key).isLocked();
    }

    @Override
    public String getHolder(String group, String key) {
        return locker.getLock(group,key).getName();
    }
}
